package processor;

import entity.Message;

import java.io.*;
import java.net.Socket;

public class Client {

    private static InputStream in = null;
    private static PrintWriter out = null;
    private static OutputStream oos = null;

    public static final String SERVER_ADDRESS = "127.0.0.1";

    public void sendMessage(Message msg) {
        try {
            Socket socket = new Socket(SERVER_ADDRESS, ChatServer.SERVER_PORT);
//            in = new BufferedReader(new InputStreamReader(socket.getInputStream()));

            in = new ObjectInputStream(socket.getInputStream());
            oos = new ObjectOutputStream(socket.getOutputStream());
            ((ObjectOutputStream) oos).writeObject(msg);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (in != null) {
                    in.close();
                }
            } catch (IOException ein) {
                ein.printStackTrace();
            }

            try {
                if (oos != null) {
                    oos.close();
                }
            } catch (IOException ein) {
                ein.printStackTrace();
            }
        }
    }

}
